define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'speech/grade/index?speech_id=' + $('#speech_id').text(),
                    // add_url: 'speech/grade/add?speech_id=' + $('#speech_id').text(),
                    edit_url: 'speech/grade/edit?speech_id=' + $('#speech_id').text(),
                    // del_url: 'speech/grade/del',
                    // multi_url: 'speech/grade/multi',
                    table: 'speech_grade',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                pageSize: 20,
                pageList: [20, 50],
                clickToSelect: false,
                dblClickToEdit: false,
                singleSelect: false,
                columns: [
                    [
                        // {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'speech_id', title: __('Speech_id')},
                        // {field: 'admin_id', title: __('Admin_id')},

                        {
                            field: 'name',
                            title: __('Name')
                        },

                        {
                            field: 'calltime',
                            title: __('Calltime'),
                            operate: false,
                            searchList: {
                                "2) unsigne": __('2) unsigne')
                            }
                        },
                        // {field: 'routernum', title: __('Routernum')},
                        // {field: 'routernum_text', title: __('Routernum'), operate:false},
                        {
                            field: 'faqnum',
                            title: __('Faqnum')
                        },
                        // {field: 'statis', title: __('Statis'),editable:false},
                        {
                            field: 'speech.name',
                            title: __('Speech.name')
                        },
                        {
                            field: 'admin.nickname',
                            title: __('销售代表')
                        },

                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'admin.id', title: __('Admin.id')},
                        // {field: 'admin.admin_id', title: __('Admin.admin_id')},
                        // {field: 'admin.username', title: __('Admin.username')},

                        // {field: 'admin.password', title: __('Admin.password')},
                        // {field: 'admin.salt', title: __('Admin.salt')},
                        // {field: 'admin.avatar', title: __('Admin.avatar')},
                        // {field: 'admin.email', title: __('Admin.email')},
                        // {field: 'admin.extension', title: __('Admin.extension')},
                        // {field: 'admin.extension_password', title: __('Admin.extension_password')},
                        // {field: 'admin.loginfailure', title: __('Admin.loginfailure')},
                        // {field: 'admin.logintime', title: __('Admin.logintime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'admin.createtime', title: __('Admin.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'admin.updatetime', title: __('Admin.updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'admin.token', title: __('Admin.token')},
                        // {field: 'admin.status', title: __('Admin.status'), formatter: Table.api.formatter.status},
                        // {field: 'speech.id', title: __('Speech.id')},

                        // {field: 'speech.admin_id', title: __('Speech.admin_id')},
                        // {field: 'speech.industry', title: __('Speech.industry')},
                        // {field: 'speech.createtime', title: __('Speech.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'speech.updatetime', title: __('Speech.updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});